IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' 
			AND name = 'sp_MetaType_SelectByName')
	BEGIN
		DROP  Procedure  sp_MetaType_SelectByName
	END

GO

Create Procedure sp_MetaType_SelectByName
(
	@MET_NAME varchar(255)
)
AS
BEGIN
    SELECT MET_ID,MET_CODE,MET_DESCRIPTION
	FROM METATYPE
	WHERE MET_CODE=@MET_NAME
END

GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' 
			AND name = 'ConvertToMetatype')
	BEGIN
		DROP  Procedure  ConvertToMetatype
	END

GO

Create Procedure ConvertToMetatype
(
	@TYP_NAME varchar(255),
	@TAR_ID uniqueidentifier
)
AS
BEGIN
    SELECT METATYPE.MET_ID,MET_CODE,MET_DESCRIPTION
	FROM METATYPE inner join METATYPE_EQUIVALENCES on 
			METATYPE.MET_ID=METATYPE_EQUIVALENCES.MET_ID
	WHERE	MET_EQU_TYPE=@TYP_NAME and
			TAR_ID=@TAR_ID
END